home *** CD-ROM | disk | FTP | other *** search
/ Deutsche Edition 1 / Deutsche Edition 1.iso / amok / amok_lha / amok24.lha / TurboFiles / asm / TurboWrite.asm < prev    next >
Assembly Source File  |  1993-08-15  |  5KB  |  153 lines

  1. ;Assemblerversion of the Procedure WriteBytes from the Module TurboFiles
  2.  
  3. ;Created: 10.6.89 by
  4. ;     Stefan Salewski
  5. ;     Stolper Weg 3
  6. ;     2160 Stade
  7.  
  8. ;-------------------------------------------------------------------
  9. ;The Modula-procedure-header:
  10. ;PROCEDURE WriteBytes(VAR f{10}:File;adr{11}:ADDRESS;len{7}:LONGINT);
  11. ;-------------------------------------------------------------------
  12. ;TYPE
  13. ;Result=(notOpen,done,notdone,openError,readError,writeError,seekError,
  14. ;        endOfFile,outOfMem,tooManyFiles);
  15. notOpen        EQU     0
  16. done           EQU     1
  17. notDone        EQU     2
  18. openError      EQU     3
  19. readError      EQU     4
  20. writeError     EQU     5
  21. seekError      EQU     6
  22. endOfFile      EQU     7
  23. outOfMem       EQU     8
  24. tooManyFile    EQU     9
  25. ;-------------------------------------------------------------------
  26. ;Modes of Dos.Seek
  27. Dos_beginning  EQU    -1
  28. Dos_current    EQU     0
  29. Dos_end        EQU     1
  30. ;-------------------------------------------------------------------
  31. ;The Modula-Datastructure:
  32. ;File=RECORD
  33. ;       fhPtr:Dos.FileHandlePtr;
  34. ;       dosBase:ADDRESS;
  35. ;       base:ADDRESS;
  36. ;       top:ADDRESS;
  37. ;       filePos:LONGINT;
  38. ;       startLength:LONGINT;
  39. ;       act:CharPtr;
  40. ;       readTop:ADDRESS;
  41. ;       writeBase:ADDRESS;
  42. ;       writeTop:ADDRESS;
  43. ;       res:Result;
  44. ;     END;
  45.  
  46. ;The offsets in the File-Variable:
  47. _fhPtr          EQU     0
  48. _dosBase        EQU     4
  49. _base           EQU     8
  50. _top            EQU     12
  51. _filePos        EQU     16
  52. _startLength    EQU     20
  53. _act            EQU     24
  54. _readTop        EQU     28
  55. _writeBase      EQU     32
  56. _writeTop       EQU     36
  57. _res            EQU     40
  58. ;-------------------------------------------------------------------
  59. ;The offsets of the Dos-functions:
  60. _Seek           EQU    -66
  61. _Write          EQU    -48
  62. _Read           EQU    -42
  63. ;-------------------------------------------------------------------
  64. ; We can use all registers except A4, A5 (and A7 of course)
  65. ; A0, A1, D0, D1 are not resistent against changes by Dos-Funktions,
  66. ; and I changes than too by myself.
  67. ; I don't use D0 and D1 as registerparameters in the ProcedureHaeder,
  68. ; because they are used to evaluate the Procedure-parameters.
  69. ;-------------------------------------------------------------------
  70. ;The variables f, adr and len I get from the Modula program
  71. ;in the registers
  72.  
  73. f           EQUR  A2; ADDRESS (The address of the file-variable)
  74. adr         EQUR  A3; VALUE   (The address to take the data from)
  75. tempAct     EQUR  D4;
  76. copyOfBase  EQUR  D5; The Values top and base (of the buffer) are constant,
  77. copyOfTop   EQUR  D6; so I copy them to registers to have quicker access.
  78. len         EQUR  D7; VALUE   (How many bytes to read) 
  79. ;-------------------------------------------------------------------
  80.  
  81. START:
  82.        CMPI.B  #done,_res(f)
  83.        BNE     TheEnd
  84.        TST.L   len
  85.        BLE     TheEnd
  86.        MOVE.L  _top(f),copyOfTop
  87.        MOVE.L  _base(f),copyOfBase;
  88.        MOVE.L  _act(f),tempAct
  89.        CMP.L   _writeTop(f),copyOfBase
  90.        BNE.S   MainLoop
  91.        MOVE.L  tempAct,_writeBase(f)
  92. MainLoop:
  93.        CMP.L   tempAct,copyOfTop
  94.        BGT.S   BufferNotFull
  95. InitBuffer:
  96.        CMP.L   _writeTop(f),copyOfBase
  97.        BEQ.S   BufferNotChanged
  98. SaveBuffer:
  99.        MOVE.L  _writeBase(f),D2
  100.        SUB.L   _readTop(f),D2
  101.        MOVEQ   #Dos_Current,D3
  102.        MOVE.L  _fhPtr(f),D1
  103.        MOVE.L  _dosBase(f),A6
  104.        JSR     _Seek(A6)
  105.        MOVE.L  _writeTop(f),D3
  106.        SUB.L   _writeBase(f),D3
  107.        MOVE.L  _fhPtr(f),D1
  108.        MOVE.L  _writeBase(f),D2
  109.        ;MOVE.L  _dosBase(f),A6; not necessary
  110.        JSR     _Write(A6)
  111.        CMP.L   D0,D3
  112.        BNE.S   WriteErr
  113.        MOVE.L  tempAct,D2
  114.        SUB.L   _writeTop(f),D2
  115.        BEQ.S   NoSeek
  116.        MOVE.L  _fhPtr(f),D1
  117.        MOVEQ   #Dos_Current,D3
  118.        JSR     _Seek(A6)
  119. NoSeek:
  120.        MOVE.L  tempAct,D0
  121.        SUB.L   _readTop(f),D0
  122.        ADD.L   D0,_filePos(f)
  123.        MOVE.L  copyOfBase,_writeTop(f)
  124. BufferNotChanged:
  125.        MOVE.L  copyOfBase,_writeBase(f)
  126.        MOVE.L  copyOfBase,tempAct
  127.        MOVE.L  copyOfBase,_readTop(f)
  128. BufferNotFull:
  129.        MOVE.L  copyOfTop,D0
  130.        SUB.L   tempAct,D0
  131.        CMP.L   len,D0
  132.        BLE.S   ok
  133.        MOVE.L  len,D0
  134. ok:
  135.        SUB.L   D0,len
  136.        SUBQ.L  #1,D0
  137.        MOVE.L  tempAct,A0
  138. CopyLoop:
  139.        MOVE.B  (adr)+,(A0)+
  140.        DBRA    D0,CopyLoop
  141.        MOVE.L  A0,tempAct
  142.        MOVE.L  A0,_writeTop(f)
  143.        TST.L   len
  144.        BNE     MainLoop
  145.        MOVE.L  tempAct,_act(f)
  146.        RTS
  147. WriteErr:
  148.        MOVE.B  #writeError,_res(f)
  149. TheEnd:
  150.        MOVE.L  tempAct,_act(f)
  151.        RTS
  152.        END
  153.